/**
 *  Copyright (C) 2011  Thomas ROBIN
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package menuitem;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import triseries.FileAcces;
import triseries.MyProperties;
import triseries.UnwatchEpisode;
import triseries.VideoFile;

/**
 * @author tshepo
 *
 */
public class OpenDir extends JMenuPlugins {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8839687628137761599L;
	private static boolean episodeItem = true;
	private static boolean display = false;

	/**
	 * 
	 */
	public OpenDir(final UnwatchEpisode uwe) {
		super("Ouvrir le Navigateur");
		display = true;
		
		final String fileLink = VideoFile.makeName(uwe.GetShow(), uwe.getSeason(), uwe.getEpisode(), uwe.GetTitle());
		

		this.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int i = 0;
				String openFile;
				do {
					if (MyProperties.nomRepDest[i].endsWith(File.separator))
						openFile = MyProperties.nomRepDest[i++]
								+ fileLink.substring(0, fileLink
										.lastIndexOf(File.separator));
					else
						openFile = MyProperties.nomRepDest[i++]
								+ File.separator
								+ fileLink.substring(0, fileLink
										.lastIndexOf(File.separator));
				} while (!FileAcces.openFile(openFile)
						&& i < MyProperties.nomRepDest.length);
			}
		});
	}
	
	/**
	 * @return the display
	 */
	public boolean isDisplay() {
		return display;
	}
	
	/**
	 * @return the episodeItem
	 */
	public boolean isEpisodeItem() {
		return episodeItem;
	}	

}
